<?php
class Table_Photos extends Zend_Db_Table_Abstract
{
    protected $_name    = 'photo';
    protected $_primary = array('PHOTO_NUMERO','VIP_NUMERO');
    protected $_sequence = true; //la table a un autoincrément
 	
  
    public function getAdressePremierePhotoByNumVip($id){
    	
         return $this->fetchRow($this
        	->select()
        	->from($this)
        	->where('PHOTO_NUMERO=1')
        	->where('VIP_NUMERO=?',$id)
        	->distinct()
        	);
    }
    
	public function getPhoByNumVip($id, $numphoto){
    	
         return $this->fetchRow($this
        	->select()
        	->from($this)
        	->where('PHOTO_NUMERO=?', $numphoto)
        	->where('VIP_NUMERO=?',$id)
        	->distinct()
        	);
    }
    
    public function getPhotosByNumVip($id){
    	
         return $this->fetchAll($this
        	->select()
        	->from($this)
        	->where('PHOTO_NUMERO != ?', '1')
        	->where('VIP_NUMERO=?',$id)
        	->distinct()
        	);
    }
    
	public function insertPhotos($numPhoto,$numVip,$adrPhoto,$titre,$commentaire){
		$data = array('PHOTO_NUMERO'=> $numPhoto,
					  'VIP_NUMERO'=> $numVip,
					  'PHOTO_ADRESSE'=> $adrPhoto,
					  'PHOTO_SUJET'=> $titre,
					  'PHOTO_COMMENTAIRE'=> $commentaire);
		$this->insert($data);
	}

	public function deletePhotos($numphoto, $numvip){
		$this->delete('PHOTO_NUMERO = '.$numphoto.' AND VIP_NUMERO ='.$numvip);
	}
	
	public function getMaxPhoto($numVip){
		return $this->fetchRow($this->select()
									->from($this, array('max'=>'MAX(PHOTO_NUMERO)'))
									->where('VIP_NUMERO=?',$numVip)
				);
	}
	
	public function deleteVip($numvip){
		$this->delete('VIP_NUMERO = '.$numvip);
	}
	
	public function updatePhoto($num, $numvip, $sujet, $comm, $ad){
		
		$data = array('PHOTO_SUJET' => $sujet,
					  'PHOTO_COMMENTAIRE' => $comm,
					  'PHOTO_ADRESSE' => $ad);
		$sql = 'PHOTO_NUMERO = ? AND VIP_NUMERO = ?';
		$values=array($num,$numvip);
		foreach($values as $value){
			$sql=$this->getAdapter()->quoteInto($sql, $value,'', 1);
		}
		return $this->update($data, $sql);
	}
}
